// pages/my/my.js
import {
  request
} from '../../api/request'
import {
  getUserInfo
} from '../../api/public'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    iscont:false,
    lookFlag: false,
    loginFlag: false,
    code: 200,
    tokens: wx.getStorageInfoSync('tokens') || false,
    userphone:''
  },
  loading(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  jumpflag(e){
    console.log('1111131232131')
    let ev = e.currentTarget.dataset.index;
    console.log(ev)
    wx.navigateTo({
      url: `/pages/order/order?flag=${ev}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */

  onShow: function () {
    let p = wx.getStorageSync('phone') ? JSON.parse(wx.getStorageSync('phone')) : '';
    let numb = p  ? `${p.slice(0,3)}****${p.slice(7)}`  :  '';
    this.setData({
      userphone:numb
    })
    if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 2
        })
      }
    // this.getUserInfo
    this.setData({
      lookFlag: false
    })
  },
  ric(){
    let that = this;
    if( !wx.getStorageSync('tokens') || that.data.userphone.length <= 0){
      wx.showModal({
        title: '提示',
        content: '您还未登录，是否进行登录',
        success(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login',
            })
            wx.hideLoading()
          } else if (res.cancel) {
           wx.hideLoading()
          }
        }
      })
      return
    }else{
      wx.navigateTo({
        url: '/pages/identity/identity',
      })
    }

  },
  cont(){
    this.setData({
      iscont:true
    })
  },
  phone(){
    wx.makePhoneCall({
      phoneNumber:"18210008508"
    })
  },
  goOrder(e) {
    if (!this.data.tokens) return wx.showToast({
      title: '请先登录在进行认证',
      icon: 'none'
    })
    var flag = e.currentTarget.dataset.flag;
    wx.navigateTo({
      url: '/pages/order/order?flag=' + -1,
    })
  },
  cls(){
    this.setData({
      iscont:false
    })
  },
  // -------------------------------------------
  // -------------------------------------------
  // -------------------------------------------
  goProblem(){
    wx.navigateTo({
      url: '/pages/problem/problem',
    })
  },
  goclause(){
    wx.navigateTo({
      url: '/pages/clause/clause',
    })
  },
  goGarage(){
    wx.navigateTo({
      url: '/pages/garage/garage',
    })
  },
  goRecharge() {
    wx.navigateTo({
      url: '/pages/recharge/recharge',
    })
  },
  goAbout() {
    wx.navigateTo({
      url: '/pages/about/about',
    })
  },
  // getUserInfo() {
  //   wx.showNavigationBarLoading();
  //   getUserInfo({}).then(e => {
  //     this.data.code = e.code;
  //     let phone = e.data.userInfo.username;
  //     e.data.userInfo.username = `${phone.slice(0,3)}****${phone.slice(7)}`
  //     this.setData({
  //       loginFlag: true,
  //       userInfo: e.data.userInfo
  //     })
  //     wx.hideNavigationBarLoading();
  //   }).catch(e => {
  //     wx.hideNavigationBarLoading();
  //   })
  // },

  goIdentity() {
    if (this.data.code == 203) return wx.navigateTo({
      url: '/pages/login/login',
    })
    if (!this.data.userInfo.identityStatus) return wx.showToast({
      title: '请先登录在进行认证',
      icon: 'none'
    })
    if (this.data.userInfo.identityStatus == 1) return wx.showToast({
      title: '认证中，请耐心等待认证结果',
      icon: 'none'
    })
    if (this.data.userInfo.identityStatus == 2) return wx.showToast({
      title: '已认证成功无需再次认证',
      icon: 'none'
    })
    wx.navigateTo({
      url: '/pages/identity/identity',
    })
  },
  changeLookFlag() {
    this.setData({
      lookFlag: !this.data.lookFlag
    })
    if (this.data.lookFlag) return this.getUserInfo()
  },
  goLogin() {
    var params = 'page=my'
    wx.navigateTo({
      url: '/pages/login/login?params=' + encodeURIComponent(params),
    })
  },
  goMore() {
    wx.navigateTo({
      url: '/pages/memberList/memberList',
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      iscont:false
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})